

#pragma once



#include <sstream>
#include <stdio.h>
#include <time.h>
#include <thread>
#include <string.h>

inline const char* __fn(const char* n)
{
	auto p = strrchr(n, '/');
	if (!p){
		p = strrchr(n,'\\');
	}
	return p ? p + 1 : n;
}

class EZLog
{
public:
	
	static void init_logfile(const std::string& file);
	

	EZLog(int level):level_(level){}

	~EZLog();
	
	template<typename _TY>
	EZLog& operator<<(const _TY& info)
	{
		buf_ << info;
		return *this;
	}

private:
	int level_;
	std::stringstream  buf_;
};

#define EZLOG_INITSTR	__fn(__FILE__) << "(" << __LINE__ << ") " \
	<< __FUNCTION__ << " thread:" << std::this_thread::get_id() << " "

#define EZLOG_DEBUG		EZLog(4) << EZLOG_INITSTR
#define EZLOG_INFO		EZLog(3) << EZLOG_INITSTR
#define EZLOG_WARN		EZLog(2) << EZLOG_INITSTR
#define EZLOG_ERROR		EZLog(1) << EZLOG_INITSTR
#define EZLOG_FATAL		EZLog(0) << EZLOG_INITSTR
